package com.mxpio.erp.common.equipment.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.mxpioframework.jpa.annotation.Generator;
import com.mxpioframework.security.annotation.Dict;
import com.mxpioframework.security.entity.BaseEntity;
import com.mxpioframework.security.entity.Dept;
import com.mxpioframework.security.entity.User;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.math.BigDecimal;
import java.util.Date;

/**
 * @Description: 库存信息
 * @Author: MxpIO
 * @Date:   2021-10-13
 * @Version: V1.0
 */
@Data
@NoArgsConstructor
@EqualsAndHashCode(callSuper=false)
@Entity
@Table(name = "MB_ERP_EQUIPMENT_STOCK_ITEM_INVENTORY")
@Schema(description="库存信息")
public class EquipmentStockItemInventory extends BaseEntity {
    private static final long serialVersionUID = 1L;

	/**id*/
    @Id
    @Generator
    @Column(name = "ID_", updatable = false)
    @Schema(description = "ID")
    private String id;
	/** 批次*/
    @Column(name = "BATCH_")
    @Schema(description = "批次")
    private String batch;
	/**当前期段期初库存数量*/
    @Column(name = "CURRENT_INIT_INV_QTY_")
    @Schema(description = "当前期段期初库存数量")
    private BigDecimal currentInitInvQty;
	/**当前台账数量*/
    @Column(name = "CURRENT_ONHAND_QTY_")
    @Schema(description = "当前台账数量")
    private BigDecimal currentOnhandQty;
	/**当前期段累计入库数量*/
    @Column(name = "CURRENT_SUMUP_IN_QTY_")
    @Schema(description = "当前期段累计入库数量")
    private BigDecimal currentSumupInQty;
	/**当前期段累计出库数量*/
    @Column(name = "CURRENT_SUMUP_OUT_QTY_")
    @Schema(description = "当前期段累计出库数量")
    private BigDecimal currentSumupOutQty;
	/**占用数量*/
    @Column(name = "ENGAGED_QTY_")
    @Schema(description = "占用数量")
    private BigDecimal engagedQty;
	/**所属部门*/
	@Dict(dicEntity = Dept.class, dicText = "deptName", dicCode = "id")
    @Column(name = "IN_HR_DEPT_ID_")
    @Schema(description = "所属部门")
    private String inHrDeptId;
	/**入库价*/
    @Column(name = "IN_PRICE_")
    @Schema(description = "入库价")
    private BigDecimal inPrice;
	/**入库登账责任人ID*/
	@Dict(dicEntity = User.class, dicText = "nickname", dicCode = "username")
    @Column(name = "IN_SYS_USER_ID_")
    @Schema(description = "入库登账责任人ID")
    private String inSysUserId;
	/**入库单申请明细中的id*/
    @Column(name = "INBOUND_APPLY_ITEM_ID_")
    @Schema(description = "入库单申请明细中的id")
    private String inboundApplyItemId;
	/**入库日期*/
	@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @Column(name = "INVENTORY_DATE_")
    @Schema(description = "入库日期")
    private Date inventoryDate;
	/**库存状态：0 可用，1 报废，2 冻结，3 盘点*/
	@Dict(dicCode = "inventory_status")
    @Column(name = "INVENTORY_STATUS_")
    @Schema(description = "库存状态：0 可用，1 报废，2 冻结，3 盘点")
    private Integer inventoryStatus;
	/**是否删除*/
    @Column(name = "IS_DELETE_")
    @Schema(description = "是否删除")
    private Integer isDelete;
	/**item01*/
    @Column(name = "item_01_")
    @Schema(description = "item01")
    private String item_01;
	/**item02*/
    @Column(name = "item_02_")
    @Schema(description = "item02")
    private String item_02;
	/**item03*/
    @Column(name = "item_03_")
    @Schema(description = "item03")
    private String item_03;
	/**item04*/
    @Column(name = "item_04_")
    @Schema(description = "item04")
    private String item_04;
	/**item05*/
    @Column(name = "item_05_")
    @Schema(description = "item05")
    private String item_05;
	/**item06*/
    @Column(name = "item_06_")
    @Schema(description = "item06")
    private String item_06;
	/** RFID值预留字段*/
    @Column(name = "LASTER_CODE_")
    @Schema(description = "RFID值预留字段")
    private String lasterCode;
	/**二维码预留字段*/
    @Column(name = "QR_CODE_")
    @Schema(description = "二维码预留字段")
    private String qrCode;
	/**合格证号*/
    @Column(name = "QUALITY_CODE_")
    @Schema(description = "合格证号")
    private String qualityCode;
	/** 超期日期*/
	@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @Column(name = "REJECT_DATE_")
    @Schema(description = "超期日期")
    private Date rejectDate;
	/**版本*/
    @Column(name = "VERSION_")
    @Schema(description = "版本")
    private Integer version;
	/**仓库id*/
	@Dict(dicEntity = EquipmentStock.class, dicText = "stock_name", dicCode = "id")
    @Column(name = "STOCK_ID_")
    @Schema(description = "仓库id")
    private String stockId;
	/**供应商id*/
	@Dict(dicEntity = EquipmentMaterial.class, dicText = "name", dicCode = "id")
    @Column(name = "MERCHANTS_ID_")
    @Schema(description = "供应商id")
    private String merchantsId;
	/**物料id*/
	@Dict(dicEntity = EquipmentMaterial.class, dicText = "name", dicCode = "id")
    @Column(name = "MATERIALS_ID_")
    @Schema(description = "物料id")
    private String materialsId;
	/**货架id*/
    // todo entity缺失
//	@Dict(dicEntity = EquipmentStockShelf.class, dicText = "code", dicCode = "id")
    @Column(name = "SHELF_ID_")
    @Schema(description = "货架id")
    private String shelfId;
	/**库位*/
	@Dict(dicEntity =EquipmentStockLocation.class, dicText = "locationName", dicCode = "id")
    @Column(name = "STOCKLOCATION_")
    @Schema(description = "货架id")
    private String stocklocation;

	public EquipmentStockItemInventory(EquipmentStockRkApply rkApply, EquipmentStockRkApplyItem item){
		this.batch = item.getBatchNo();
		this.currentOnhandQty = BigDecimal.valueOf(item.getThisOptNum());
		this.inPrice = item.getRealPrice();
		this.inboundApplyItemId = item.getId();
		this.inventoryDate = new Date();
		this.inventoryStatus = 0;
		this.isDelete = 0;
		this.version = 0;
		this.stockId = rkApply.getStockId();
		this.merchantsId = item.getVendorId();
		this.materialsId = item.getMaterialsId();
		this.stocklocation = item.getStocklocation();
	}
}
